package luo_xiang_yuan;

public class LUO_XIANG_YUAN_Q1 {
    private  int maxSize = 10;
    private int[] stack = new int[maxSize];
    private int top = -1;
    //栈满
    public boolean isFull(){
        return top == maxSize;
    }
    //栈空
    public boolean isEmpty(){
        return top == -1;
    }
    //输入
    public  void push(int value){
        if(isFull ()){
            System.out.println ("已满");
        }
        top++;
        stack[top] = value;
    }
    //输出栈顶
    public int pop(){
        if(isEmpty ()){
            System.out.println ("空栈");
        }
        int value = stack[top];
        top--;
        return value;
    }
    //输出栈中的全部数据
    public void popAll(){
        if(isEmpty ()){
            System.out.println ("空栈");
        }
        for(int i = top;i >=0; i--){
            System.out.println (stack[i]);
        }
       top=-1;
    }

    public int size(){
        return this.top+1;//top的初始值为-1
    }

    public static void main(String[] args) {
          LUO_XIANG_YUAN_Q1 as = new LUO_XIANG_YUAN_Q1 ();
          as.push ( 1 );
          as.push ( 2 );
          as.push ( 3 );
          as.push ( 4 );
          System.out.println (as.pop ());
          System.out.println (as.pop ());
//          as.popAll ();
          System.out.println ("长度"+as.size ());
    }

}
